package com.fcl.oschina;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.fcl.mylibrary.reflect.ViewInject;
import com.fcl.mylibrary.reflect.ViewInjectUtils;
import com.fcl.oschina.ui.activity.UserInfoActivity;
import com.fcl.oschina.ui.fragment.HomeFragment;

public class MainActivity extends AppCompatActivity {


    @ViewInject(R.id.draw_layout)
    DrawerLayout mDrawerLayout;

    @ViewInject(R.id.toolbar)
    Toolbar mToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        startActivity(new Intent(this, UserInfoActivity.class));
        ViewInjectUtils.inject(this);
        init();
    }

    public void replaceFragment(int layoutid, Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(layoutid, fragment).commitAllowingStateLoss();
    }

    public void initToolbar() {
        mToolbar.setTitle(R.string.home);
        mToolbar.setTitleTextColor(getResources().getColor(R.color.white));
        setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
        if (null != actionBar) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    private void init() {
        initToolbar();
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
                mDrawerLayout,
                mToolbar,
                R.string.app_name,
                R.string.app_name);
        toggle.syncState();
        mDrawerLayout.addDrawerListener(toggle);
        replaceFragment(R.id.content, new HomeFragment());
    }
}
